/**
 * 数据库配置和表索引
 * @author whyccup
 */
const mongoose = require('mongoose')
const db = require('../config').db
const mongodb = db.mongodb
const log = require('../config').log

// mongodb连接
mongoose.connect(`mongodb://${mongodb.host}:${mongodb.port}/${mongodb.name}`, {
  useNewUrlParser: true
}, (err) => {
  // 链接成功
  console.log(`连接${mongodb.name}成功`)
  // 链接错误
  if (err) {
    log.error(`连接${mongodb.name}失败,错误:${err.message}`)
    process.exit(1)
  }
})

// 使用本地Promise
mongoose.Promise = Promise

// 表
const account = require('./account')

module.exports = {
  account
}